package com.tanhua.dubbo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.domain.SoulTest.UserSoulScore;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author 钱柏羽
 * 计算灵魂分数sql
 */
public interface SoulScoreMapper extends BaseMapper<UserSoulScore> {
    @Select("SELECT SUM(score) FROM tb_survey_score WHERE (qid,oid) IN ${sqlQuery}")
    Integer getSoulScore(@Param("sqlQuery") String sqlQuery);

    @Select("SELECT id FROM tb_conclusion_info WHERE #{reportScore} BETWEEN low AND high")
    String getScoreType(@Param("reportScore") String reportScore);

    @Select("SELECT score FROM `tb_survey_user_score` WHERE user_id=#{userId} and Type=#{facility}")
    Integer findTestScore(@Param("userId") Long userId,@Param("facility")  String facility);

    @Select("SELECT TYPE FROM `tb_survey_user_score` WHERE score=#{userId} AND TYPE='${facility}'")
    String findTestType(@Param("userId") Long userId,@Param("facility") String facility);

    @Insert("INSERT INTO tb_survey_user_score VALUES(#{userId},#{surveyScore},#{facility})")
    void save(Long userId, Integer surveyScore, String facility);
}
